import { defineStore } from "pinia"
import { KeepAliveState } from "@/stores/interface"

export const useKeepAliveStore = defineStore({
  id: "KeepAliveStore",
  state: (): KeepAliveState => ({
    keepAliveName: []
  }),
  actions: {
    // 添加 持久化
    async addKeepAliveName(name: string) {
      !this.keepAliveName.includes(name) && this.keepAliveName.push(name)
    },
    // 移除 持久化
    async removeKeepAliveName(name: string) {
      this.keepAliveName = this.keepAliveName.filter(item => item !== name)
    },
    // 设置 持久化
    async setKeepAliveName(keepAliveName: string[] = []) {
      this.keepAliveName = keepAliveName
    }
  }
})
